package com.patchmanage.back.controller;


import cn.hutool.core.lang.Dict;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.patchmanage.back.entity.InventoryPackage;
import com.patchmanage.back.result.Result;
import com.patchmanage.back.service.IInventoryPackageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author huizhao
 * @since 2021-07-11
 */
@Api(value = " 资产包详情 controller", tags = {"资产包详情 Api"})
@RestController
@RequestMapping("/back/inventorypackage")
public class InventoryPackageController {

    @Autowired
    private IInventoryPackageService iInventoryPackageService;

    /**
     * 获取资产包列表
     * @param dict
     * @return
     */
    @ApiOperation(value = "获取资产包列表接口", notes = "获取资产包列表接口")
    @RequestMapping(value = "list", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "hostname", value = "hostname", required = false, dataType = "String", paramType = "body")
    })
    public Result<IPage<InventoryPackage>> list(@RequestBody Dict dict) {

        Integer pageNo = dict.getInt("pageNo");
        Integer pageSize = dict.getInt("pageSize");
        IPage<InventoryPackage> page = new Page(pageNo, pageSize);

        QueryWrapper<InventoryPackage> queryWrapper = new QueryWrapper<InventoryPackage>();
        queryWrapper.eq("hostname",dict.getStr("hostname"));
        queryWrapper.orderByDesc("utime");

        return Result.success(iInventoryPackageService.page(page,queryWrapper));
    }
}
